<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('新增个人帖子信息管理')" />
<div th:replace="/foreground/client/header::header(心理社区,null)"></div>
<th:block th:include="include :: datetimepicker-css" />
<th:block th:include="include :: summernote-css" />
<th:block th:include="include :: bootstrap-fileinput-css"/>

<link th:href="@{/ruoyi/css/ry-ui.css?v=4.7.0}" rel="stylesheet"/>
</head>
<body class="white-bg" >
<div class="wrapper wrapper-content animated fadeInRight ibox-content" style="margin-top: 80px">
    <form class="form-horizontal m" id="form-posts_user-add">
        <h4 class="form-header h4" style="font-size: 18px;color: #5f5f5f">发布帖子</h4>
        <div class="form-group" hidden>
            <label class="col-sm-3 control-label">发帖用户id：</label>
            <div class="col-sm-8">
                <input name="userId" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">帖子标题：</label>
            <div class="col-sm-8">
                <input name="postsTitle" id="postsTitle" class="form-control" type="text"minlength="5"  maxlength="46" placeholder="标题字数限制46">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">帖子内容：</label>
            <div class="col-sm-8">
                <input type="hidden" class="form-control" name="postsContent"  >
                <div class="summernote" id="postsContent"></div>
            </div>
        </div>
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">帖子封面图片存放地址：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input type="hidden" name="postsImage">-->
<!--                <div class="file-loading">-->
<!--                    <input class="form-control file-upload" id="postsImage" name="file" type="file">-->
<!--                </div>-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group" hidden>
            <label class="col-sm-3 control-label">帖子的回复的数量：</label>
            <div class="col-sm-8">
                <input name="commentNum" class="form-control" th:value="0" type="text" >
            </div>
        </div>
        <div class="form-group" hidden>
            <label class="col-sm-3 control-label">最后回复者id：</label>
            <div class="col-sm-8">
                <input name="lastComUserId" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group" hidden>
            <label class="col-sm-3 control-label">最后回复时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="lastComTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>


                <button onclick="submitHandler()"
                        style="float: right;color: #ffffff;font-weight:bold;font-size:18px;display:block ;margin-right:158px;border-radius: 12px;width: 160px;height: 40px;background-color: #30b869"
                >发布</button>
                <button onclick="toBack()"
                        style="float: right;text-align: center;display:block ;margin-right:100px;padding:8px 5px 5px 5px;color: #ffffff;font-weight:bold;font-size:18px; border-radius: 12px;width: 160px;height: 40px;background-color: #76acb8"
                >返回</button>



    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: summernote-js" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:src="@{/ruoyi/js/ry-ui.js?v=4.7.0}"></script>
<script th:inline="javascript">
    var prefix = ctx + "system/posts_user"
    $("#form-posts_user-add").validate({
        focusCleanup: true,
        postsTitle:{
            maxLength: 50,
            message:'................'
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.saveComment(prefix + "/addPosts", $('#form-posts_user-add').serialize( ));
            alert("发帖成功");
            window.parent.close();
        }
    }

    function toBack() {
            window.parent.close();
    }

    $(".file-upload").fileinput({
        uploadUrl: ctx + 'common/upload',
        maxFileCount: 1,
        autoReplace: true
    }).on('fileuploaded', function (event, data, previewId, index) {
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    })


    $(function() {
        $('.summernote').summernote({
            lang: 'zh-CN',
            minHeight : 260,
            placeholder: '请输入内容',//提示语
            maxLength: 500,
            dialogsInBody: true,
            callbacks: {
                onChange: function(contents, $edittable) {
                    $("input[name='" + this.id + "']").val(contents);
                },
                onImageUpload: function(files) {
                    var obj = this;
                    var data = new FormData();
                    data.append("file", files[0]);
                    $.ajax({
                        type: "post",
                        url: ctx + "common/upload",
                        data: data,
                        cache: false,
                        contentType: false,
                        processData: false,
                        dataType: 'json',
                        success: function(result) {
                            if (result.code == web_status.SUCCESS) {
                                $('#' + obj.id).summernote('insertImage', result.url);
                            } else {
                                $.modal.alertError(result.msg);
                            }
                        },
                        error: function(error) {
                            $.modal.alertWarning("图片上传失败。");
                        }
                    });
                }
            }
        });
    });


</script>
</body>
</html>